/**
 * \file    coder.h
 * \brief   Action(de)coder.
 * \author  Jérôme LAURENS
 * \version 0.1
 * \date    November 20, 2014
 *
 * Reads a LALR(1) grammar, generates a parser based on a template file.
 * This is based on lemon parser generator, but has strongly been
 * revisited.
 *
 */

#ifndef CODER_H
#define CODER_H

#include "common.h"
#include "transaction.h"

LPP_NAMESPACE_BEGIN

typedef std::reference_wrapper<Builder const> BuilderRef;

class Coder
{
public:
    Coder(Builder const & builder)
        : builder_m(std::ref(builder)) {}
    ActionCode code(const ActionRef &action) const;
    ActionRef const action(ActionCode const action, SymbolRef const & lookahead) const;
    ActionRef const action(StateRef const & state, SymbolRef const & lookahead) const;
    Transaction const transaction(StateRef const & state, SymbolRef const & lookahead) const;
#ifndef NDEBUG
    void simple_encode(StateRef const & state, ActionRef const & action);
    ActionRef const simple_action(StateRef const & state, SymbolRef const & lookahead) const;
#endif
    Builder const & builder() const {
        return builder_m;
    }
    Generator const & generator() const;
    GrammarRef const & grammar() const;
#ifndef NDEBUG
    Transactions const simple_action_table() const {
        return simple_action_table_m;
    }
#endif
private:
    BuilderRef const builder_m;
#ifndef NDEBUG
    Transactions simple_action_table_m;
#endif
};

LPP_NAMESPACE_END

#endif // CODER_H
